//
//  LGKNoteManager.m
//  LGKNote
//
//  Created by 刘亚军 on 2023/5/26.
//

#import "LGKNoteManager.h"
#import "LGKConst.h"
#import <YJPresentAnimation/YJPresentPushAnimation.h>
#import <YJPresentAnimation/YJPresentPopAnimation.h>
@interface LGKNoteManager ()<UIViewControllerTransitioningDelegate>
@property (nonatomic,strong) NSBundle *noteBundle;
@end
@implementation LGKNoteManager
+ (LGKNoteManager *)defaultManager{
    static LGKNoteManager * macro = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        macro = [[LGKNoteManager alloc]init];
        macro.noteBundle = [NSBundle yj_bundleWithCustomClass:NSClassFromString(@"LGKNoteBaseViewController") bundleName:@"LGKNote"];
        macro.subjectName = @"英语";
    });
    return macro;
}
- (void)setCpbaseServerUrl:(NSString *)cpbaseServerUrl{
    if (!IsStrEmpty(_cpbaseServerUrl) && ![_cpbaseServerUrl isEqualToString:cpbaseServerUrl]){
        _noteApi = @"";
    }
    _cpbaseServerUrl = cpbaseServerUrl;
}
- (void)presentNotePageFromController:(UIViewController *)fromController{
      __weak typeof(self) weakSelf = self;
    dispatch_async(dispatch_get_main_queue(), ^{
        UIViewController *vc = [[NSClassFromString(@"LGKNoteMainController") alloc] init];
        UINavigationController *navi = [[NSClassFromString(@"LGKNoteBaseNavigationController") alloc] initWithRootViewController:vc];
        navi.transitioningDelegate = weakSelf;
        navi.modalPresentationStyle = UIModalPresentationFullScreen;
        [fromController presentViewController:navi animated:YES completion:nil];
    });
}

#pragma mark UIViewControllerTransitioningDelegate
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source{
    return [YJPresentPushAnimation new];
}
- (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed{
    return [YJPresentPopAnimation new];
}
@end
